home *** CD-ROM | disk | FTP | other *** search
- Path: news.uh.edu!usenet
- From: Sensarn <txs53132@bayou.uh.edu>
- Newsgroups: comp.lang.c++
- Subject: Re: Basic header file broblem in BC 4.5
- Date: 21 Jan 1996 22:26:17 GMT
- Organization: AEtna Insurance Agency
- Message-ID: <4duei9$pgb@masala.cc.uh.edu>
- References: <4du8q0$k1h@yuggoth.ucsb.edu>
- NNTP-Posting-Host: sip-14262.public-dialups.uh.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1 (Windows; U; 16bit)
-
- The CPP files work seperately:
-
- If your project window looked like this:
-
- main.cpp
- function.cpp
-
- You simply have two CPP files that are to be compiled together. Each
- file needs prototypes. The main.cpp file is the one with the main()
- routine -- prototypes for main.cpp are located in main.cpp. To use the
- functions in function.cpp, main.cpp must also contain the prototypes for
- function.cpp. Therefore, you create a header file for function.cpp --
- we'll call it function.h. In the header file, you have prototypes and
- structures:
-
- void xxxx(void); //Whatever
- ..
-
- To use this header file, you add:
-
- #include "function.h"
-
- to main.cpp. This is EXACTLY the same thing as copying ALL of the data
- from function.h to main.cpp (the first line of function.h goes on the
- line where #include "function.h" is located). This means that if the
- first line in function.h is:
-
- void nothing(void);
-
- the main.cpp file would look somewhat like this:
-
- #include "function.h" //This part may be deleted -- I don't know exactly
- //how the compiler works.
- void nothing(void);
-
- Good so far. Now main.cpp has all the prototypes for function.cpp.
- Unfortunately, in our example, function.cpp does not contain any
- prototypes. We must also include function.h to this module. Now we
- can't define global variables in function.h; we would receive an error
- because we defined the variables twice (once in function.cpp and once in
- main.cpp). To do this, we create main.h. The global variables are
- defined here. Main.h is #included in main.cpp but NOT in function.cpp.
- Good for us; our globals are only defined once.
-
- This may not be the best way to organize your work, but I haven't had any
- problems with it.
-
- Steven Sensarn - txs53132@bayou.uh.edu
-
-